package com.zhao.concreteMediator;

import com.zhao.colleague.Colleague;
import com.zhao.mediator.Mediator;

import java.util.HashMap;
import java.util.Map;

public class HomeMediator extends Mediator {

    private Map<Colleague, String> colleagues = new HashMap<>();

    @Override
    public void add(Colleague colleague, String role) {
        colleagues.put(colleague, role);
    }

    @Override
    public void delete(Colleague colleague) {
        colleagues.remove(colleague);
    }

    @Override
    public void contact(Colleague colleague) {
        if (colleagues.get(colleague).equals("租房者")) {
            colleagues.forEach((k, v) -> {
                if (v.equals("房东")) {
                    k.getMessage();
                }
            });
        } else if (colleagues.get(colleague).equals("房东")) {
            colleagues.forEach((k, v) -> {
                if (v.equals("租房者")) {
                    k.getMessage();
                }
            });
        } else {
            System.out.println("不在代理范围...");
        }
    }
}
